package com.atguigu.gmall.product.rest;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;


    /**
     * /admin/product/baseTrademark/{page}/{limit}
     */
    @GetMapping("/{page}/{limit}")
    public Result baseTrademark(@PathVariable Long page
                                ,@PathVariable Long limit
                                ) {
        return Result.ok(baseTrademarkService.page(new Page<BaseTrademark>(page,limit)));
    }


    /**
     * h/admin/product/baseTrademark/save
     *
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @GetMapping("/get/{id}")
    public Result getBaseTrademarkById(@PathVariable Long id) {
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @PutMapping("update")
    public Result updateBaseTrademarkById(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @DeleteMapping("/remove/{id}")
    public Result removeBaseTrademarkById(@PathVariable Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * /admin/product/baseTrademark/getTrademarkList
     * 查找所有品牌信息
      * @return
     */
    @GetMapping("/getTrademarkList")
    public Result getTrademarkList() {
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }

}
